<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property string $name 点位名称
 * @property string $address 点位地址
 * @property string $message 自定义报文
 * @property integer $type 字段类型
 * @property integer $num 读取的数量
 * @property integer $device_id 设备id
 * @property integer $model_id 所属型号
 * @property mixed $encode 报文编码
 * @property string $field_name 字段名称
 * @property integer $field_type 字段类型
 * @property integer $accuracy 精度
 * @property string $created_time 创建时间
 * @property mixed $updated_time
 */
class IotSignal extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'iot_signal';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    protected $appends=[
        "new_address"
    ];

    public function getNewAddressAttribute(): string
    {
        $type = $this->type;
        $field_type = $this->field_type;
        $field_bit_address = $this->field_bit_address;
        $byte_area_array = $this->byte_area_array;
        $name_fd = $this->address;
        if ($type==1 &&$field_type==0 && $field_bit_address && $byte_area_array){
            return $name_fd."-{$field_bit_address}";
        }
        return $name_fd;
    }

}
